package reznic.ga.tracker.objects;

import java.io.IOException;
import reznic.ga.tracker.utils.StringUtils;

/**
 *
 * @author Reznic Alexandru
 *
 */
public class TrackPageview {

    private String hostName = null;
    private String page = null;
    private String title = null;
    private boolean mobile;

    /**
     * Page Tracking <br>
     * &dh=mydemo.com // Document hostname.<br>
     * &dp=/home // Page.<br>
     * &dt=homepage // Title.<br>
     */
    public TrackPageview() {
    }

    public TrackPageview(String hostName, String page, String title) {
        this.hostName = hostName;
        this.page = page;
        this.title = title;
    }

    public String buildURL() throws IOException {
        StringBuilder buf = new StringBuilder();
        if (StringUtils.isNotBlank(hostName)) {
            buf.append("&dh=").append(StringUtils.getURLString(hostName));
        }
        if (StringUtils.isNotBlank(page)) {
            if (!page.startsWith("/")) {
                page = "/" + page;
            }
            buf.append("&dp=").append(StringUtils.getURLString(page));
        }
        if (StringUtils.isNotBlank(title)) {
            buf.append("&dt=").append(StringUtils.getURLString(title));
        }

        return buf.toString();
    }

    public boolean isMobile() {
        return mobile;
    }

    public void setMobile(boolean mobile) {
        this.mobile = mobile;
    }

    /**
     * @return the hostName
     */
    public String getHostName() {
        return hostName;
    }

    /**
     * @param hostName the hostName to set
     */
    public void setHostName(String hostName) {
        this.hostName = hostName;
    }

    /**
     * @return the page
     */
    public String getPage() {
        return page;
    }

    /**
     * @param page the page to set
     */
    public void setPage(String page) {
        this.page = page;
    }

    /**
     * @return the title
     */
    public String getTitle() {
        return title;
    }

    /**
     * @param title the title to set
     */
    public void setTitle(String title) {
        this.title = title;
    }
}
